package cuit.pymjl;

import io.netty.util.concurrent.FastThreadLocal;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author Pymjl
 * @version 1.0
 * @date 2022/7/21 16:11
 **/
public class Context {
    private static FastThreadLocal<String> fastThreadLocal = new FastThreadLocal<>();

    public static void main(String[] args) {
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(3, 3,
                0, TimeUnit.SECONDS, new ArrayBlockingQueue<>(5));
        threadPoolExecutor.execute(() -> {
            try {
                fastThreadLocal.set("hello");
                fastThreadLocal.set("python");
                System.out.println(fastThreadLocal.get());
            } finally {
                fastThreadLocal.remove();
            }
        });
        threadPoolExecutor.execute(() -> {
            try {
                fastThreadLocal.set(Thread.currentThread().getName() + ": 222222");
                System.out.println(fastThreadLocal.get());
            } finally {
                fastThreadLocal.remove();
            }
        });
        threadPoolExecutor.execute(() -> {
            try {
                fastThreadLocal.set(Thread.currentThread().getName() + ": 333333");
                System.out.println(fastThreadLocal.get());
            } finally {
                fastThreadLocal.remove();
            }
        });
        threadPoolExecutor.shutdown();
    }

}
